/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2024-06-11 22:34:25
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-06-16 22:10:53
 * @FilePath: /chat-ai-plus/src/store/modules/user.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
/*
 * @Author: Leo.wang wanglizhigs@163.com
 * @Date: 2024-06-03 22:57:27
 * @LastEditors: Leo.wang wanglizhigs@163.com
 * @LastEditTime: 2024-06-11 22:34:44
 * @FilePath: /chat-ai-plus/src/store/modules/robot.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia';

import { login, getUserInfo, modifyPhone,modifyEmail } from '@/api/user.api';

const useUserStore = defineStore({
  id: 'userStore',
  state: () => ({
    user: undefined,

  }),
  getters: {},
  actions: {
    login(data) {
      return login(data);
    },
    clearUser() {
      this.user = undefined;
    },
    getUserInfo() {
      return getUserInfo().then(response => {
        const { status, data, msg } = response.data;
        if (status === 200) {
          this.user = data;
        } else {
          uni.showToast({
            title: msg,
          });
        }
        return response;
      });
    },

    modifyPhone(data) {
      modifyPhone(data).then()
    },
    modifyEmail(data) {
      modifyEmail(data).then()
    }
  },
  persist: {
    enabled: true,
    strategies: [
      {
        storage: localStorage,
        paths: ['user'],
      },
    ],
  },
});
export default useUserStore;

